package fms.msgupcenter.protocols;

import fms.msgupcenter.protocols.uplinkmsg.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * User: adcc
 * Date: 14-6-11
 * Time: 下午4:27
 * To change this template use File | Settings | File Templates.
 */
public class Test {
    public static void main(String[]args){
        UplinkMsgProtocol uplinkMsgProtocol =  new UplinkMsgProtocol();
        UplinkMsgProtocolBody body = uplinkMsgProtocol.body;
        UplinkMessage uplinkMessage = body.uplinkMessage;
        UplinkMsgHead uplinkMsgHead = new UplinkMsgHead();
        uplinkMsgHead.setAppUpMsgId(UUID.randomUUID().toString());
//        uplinkMsgHead.setAppUpMsgType("FREETEXT");
        uplinkMsgHead.setAn("B-5678");
//        uplinkMsgHead.setFi("MU3588");
//        uplinkMsgHead.setOriginAirport("");
//        uplinkMsgHead.setDestAirport("");
        uplinkMsgHead.setSmi("CMD");
//        uplinkMsgHead.setAutoreply(true);
//        uplinkMsgHead.setApptype("FMS");
//        uplinkMsgHead.setAirline("");
//        uplinkMsgHead.setOnlyLastReply(true);
//        uplinkMsgHead.setTag("");

        SendRules sendRules = new SendRules();
        List<Sender> senders = new ArrayList<Sender>();
        Sender sender = new Sender(SendRules.SenderType.Default,"","",0,0);
        senders.add(sender);
        sendRules.setAllowMaxTime(600);
        sendRules.setSenders(senders);
//        uplinkMsgHead.setSendRules(sendRules);

        UplinkMessageData uplinkMessageData = new UplinkMessageData("");
        uplinkMessageData.setText("");

        uplinkMessage.setHead(uplinkMsgHead);
        uplinkMessage.setData(uplinkMessageData);
        uplinkMessage.setSendRules(sendRules);
        uplinkMessage.setMsg("");

        String s ="";
        try {

            s =   AcarsProtocol.Serialize(uplinkMsgProtocol);
            UplinkMsgProtocol protocol = (UplinkMsgProtocol) AcarsProtocol.Deserialize(
                    s, UplinkMsgProtocol.class);
            System.out.print(protocol.body.uplinkMessage.getSkylinkType());


          String   ss="<?xml version=\"1.0\" encoding=\"utf-8\"?><acars xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" v=\"2.0\"><body id=\"SAFE\">\n" +
                    "<skylink type=\"UPLINKACK\" version=\"3.0\">\n" +
                    "<head appUpMsgId=\"02fb8c70-2b29-48c5-9bb1-5cdfb9810016\" an=\"B-6619\" fi=\"HU1161\" destination=\"HAKDPHU\" signature=\"DDLXCXA\" smi=\"FML\" dsp=\"DDL\" rgs=\"XXA\" rgsTime=\"2014-11-17 2:46:11\" msn=\"F33A\" maNum=\"001\" ackType=\"MANU\" state=\"8\" errorCode=\"\" appName=\"FMS\" appUpMsgType=\"\" upsender=\"\">\n" +
                    "<tag></tag>\n" +
                    "</head>\n" +
                    "</skylink></body></acars>";

            WindMsgProtocol protocol1 = (WindMsgProtocol) AcarsProtocol.Deserialize(
                    ss, WindMsgProtocol.class);
            String appUpMsgId=protocol1.body.windMessage.getHead().getAppUpMsgId();
            String an=protocol1.body.windMessage.getHead().getAn();
            String status=protocol1.body.windMessage.getHead().getState();
            System.out.println(appUpMsgId+"appUpMsgId===============");
            System.out.println(status+"status===============");
            System.out.println(an);
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}
